package ch.zbw.swt.sysventory.network;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.concurrent.Callable;

public class CalculateReachabelIpPart implements Callable<CalculateReachabelIpPart> {

	private String ip;
	private boolean IpReachebel;

	public CalculateReachabelIpPart(String ip) {

		this.ip = ip;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public boolean isIpReachebel() {
		return IpReachebel;
	}

	public void setIpReachebel(boolean ipReachebel) {
		IpReachebel = ipReachebel;
	}

	private boolean pingBySocket(String ip) {
		boolean isReachable = false;
		Socket socket = new Socket();
		try {
			socket.connect(new InetSocketAddress(ip, 135), 150);
			isReachable = true;
		} catch (IOException e) {
			isReachable = false;
		}

		return isReachable;
	}
	

	public CalculateReachabelIpPart call() throws Exception {

		Socket socket = new Socket();

		try {
			socket.connect(new InetSocketAddress(ip, 135), 150);
			IpReachebel = true;
			return this;
		} catch (IOException e) {
			return this;
		}

	}

}
